/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package converters;

import com.mycompany.psc.ejb.UsersManager;
import com.mycompany.psc.entities.Users;
import javax.ejb.EJB;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author A7med
 */
@FacesConverter(forClass = Users.class,value = "userConverter")
public class UsersConverter implements Converter{

    @EJB
    UsersManager um;
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
       
        return um.getUserByName(value);
        
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if(value instanceof Users){
            Users u=(Users)value;
    
        return u.getName();
        }else{
            return "no value";
        }
       
    }
    
}
